package com.collectplus.express.menu;

import android.os.Bundle;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.collectplus.express.BaseActivity;
import com.collectplus.express.R;
import com.collectplus.express.logic.AppCache;
import com.collectplus.express.logic.AppHttp;
import com.collectplus.express.logic.AppResult;
import com.collectplus.express.logic.DialogMgr;
import com.collectplus.express.logic.JSON;
import com.collectplus.express.logic.MsgID;
import com.collectplus.express.model.AppConfigBean;

import droid.frame.umeng.UMeng;

/**
 * 意见反馈
 *
 * @author coffee<br>
 *         2015-11-23上午11:11:44
 */
public class FaqActivity extends BaseActivity implements OnClickListener {

    private EditText mEdit;
    private Button mOkButton;
    private TextView mServiceTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 设置底部按钮不随着软键盘上浮
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.faq);
        super.findViewById();
        setCommonTitle("意见反馈");
        mEdit = (EditText) findViewById(R.id.faq_edit);
        mOkButton = (Button) findViewById(R.id.faq_ok_button);
        mOkButton.setOnClickListener(this);
        findViewById(R.id.faq_call).setOnClickListener(this);
        //
        AppConfigBean cfg = AppCache.getAppConfig();
        mServiceTime = (TextView) findViewById(R.id.faq_service_time);
        if (cfg != null && isNotEmpty(cfg.getKfServiceTime())) {
            mServiceTime.setText(cfg.getKfServiceTime());
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.faq_call:
                UMeng.click(getContext(), "menu_faq_phone_click");
//			DialogMgr.showPhoneDialog(getContext(), mServiceTime.getText().toString());
                DialogMgr.showPhoneDialog(getContext(), null);
                break;
            case R.id.faq_ok_button:
                String s = mEdit.getText().toString();
                if (TextUtils.isEmpty(s)) {
                    showToast("请输入反馈内容");
                } else {
                    UMeng.click(getContext(), "menu_faq_affirm_click");
                    showLoadingDialog(null);
                    AppHttp.getInstance().faq(mEdit.getText().toString());
                }
                break;
        }
    }

    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            case MsgID.faq:
                cancelLoadingDialog();
                AppResult<?> result = JSON.parser(msg.obj);
                if (result.isSuccess()) {
                    showToast(getString(R.string.http_tip_faq));
                    finish();
                } else {
                    showToast(result.getMessage());
                }
                break;
        }
        return true;
    }
}
